package com.endoc.jni2learn;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import java.util.Date;

public class MainActivity extends AppCompatActivity {

    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");
    }
    String TAG ="JNIMainActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Example of a call to a native method
        TextView tv = findViewById(R.id.sample_text);
        tv.setText(stringFromJNI("java输入:"));
        functionAndPropertyFromJNI();//jni层调用java层的方法和属性
        Log.d(TAG,"java层修改后property值:"+property);
        int[] ints = {1, 2, 3, 4};
        intArrayFromJNI(ints);
        for (int i = 0; i <ints.length ; i++) {
            Log.d(TAG,"ndk层的数组"+ints[i]);
        }
    }

    public int property =1;//非静态属性
    public static int staticproperty = 2;//静态属性
    public int function(int fun, Date date, int[] arr){
        System.out.println("我是非静态方法:"+fun);
        return 0;
    }

    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    public native String stringFromJNI(String input);

    //传递数组过去,然后jni层获取数组地址,直接操作这块地址,而不是jni再拷贝一份
    public native void intArrayFromJNI(int[] a);

    /**
     * TODO 此本地方法用来调用此类的方法和属性
     */
    public native void functionAndPropertyFromJNI();

    //TODO 静态方法,c层调用java层静态方法
    public static   void functionStaticFromJNI(int fun){
        System.out.println("我是静态方法:"+fun);
    }


}
